#pragma once
#include "Vector3.h"

template <class T>
class Matrix33
{
public:
	Matrix33(void) { Identity(); }
	~Matrix33(void) {};

	void SetRows( Vector3<T>& row1, Vector3<T>& row2, Vector3<T>& row3 ); 

	void Identity();

	T Determinant() const;

	static T Determinant2by2(T m0,T m1,T m2,T m3);

	T m[9];
};

template <class T>
void Matrix33<T>::Identity()
{
	m[0] = 1; m[1] = 0; m[2] = 0;
	m[3] = 0; m[4] = 1; m[5] = 0;
	m[6] = 0; m[7] = 0; m[8] = 1;
}

template <class T>
void Matrix33<T>::SetRows( Vector3<T>& row1, Vector3<T>& row2, Vector3<T>& row3 )
{
	m[0] = row1.x; m[1] = row1.y; m[2] = row1.z;
	m[3] = row2.x; m[4] = row2.y; m[5] = row2.z;
	m[6] = row3.x; m[7] = row3.y; m[8] = row3.z;
}

template <class T>
T Matrix33<T>::Determinant() const
{
	return m[0]*Determinant2by2(m[4],m[5],m[7],m[8]) 
			- m[1]*Determinant2by2(m[3],m[5],m[6],m[8])
			+ m[2]*Determinant2by2(m[3],m[4],m[6],m[7]);
}

template <class T>
T Matrix33<T>::Determinant2by2( T m0,T m1,T m2,T m3 )
{
	return m0*m3 - m1*m2;
}